from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-07 14:02:21.210503
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 07, Aug, 2022
Time: 14:02:27
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.0596
Nobs: 741.000 HQIC: -50.4035
Log likelihood: 9381.53 FPE: 1.03835e-22
AIC: -50.6193 Det(Omega_mle): 9.20335e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296760 0.055652 5.332 0.000
L1.Burgenland 0.107833 0.036876 2.924 0.003
L1.Kärnten -0.106827 0.019544 -5.466 0.000
L1.Niederösterreich 0.206568 0.076900 2.686 0.007
L1.Oberösterreich 0.109814 0.075131 1.462 0.144
L1.Salzburg 0.254131 0.039398 6.450 0.000
L1.Steiermark 0.041865 0.051417 0.814 0.416
L1.Tirol 0.108514 0.041711 2.602 0.009
L1.Vorarlberg -0.062105 0.035863 -1.732 0.083
L1.Wien 0.048422 0.066470 0.728 0.466
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058380 0.116296 0.502 0.616
L1.Burgenland -0.032011 0.077061 -0.415 0.678
L1.Kärnten 0.047023 0.040841 1.151 0.250
L1.Niederösterreich -0.175690 0.160699 -1.093 0.274
L1.Oberösterreich 0.407259 0.157002 2.594 0.009
L1.Salzburg 0.287896 0.082332 3.497 0.000
L1.Steiermark 0.107713 0.107446 1.002 0.316
L1.Tirol 0.311431 0.087165 3.573 0.000
L1.Vorarlberg 0.025287 0.074944 0.337 0.736
L1.Wien -0.029854 0.138904 -0.215 0.830
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189404 0.028573 6.629 0.000
L1.Burgenland 0.090178 0.018933 4.763 0.000
L1.Kärnten -0.008833 0.010034 -0.880 0.379
L1.Niederösterreich 0.260427 0.039483 6.596 0.000
L1.Oberösterreich 0.138371 0.038574 3.587 0.000
L1.Salzburg 0.045425 0.020228 2.246 0.025
L1.Steiermark 0.021255 0.026399 0.805 0.421
L1.Tirol 0.093203 0.021416 4.352 0.000
L1.Vorarlberg 0.055451 0.018413 3.011 0.003
L1.Wien 0.116301 0.034128 3.408 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107440 0.029024 3.702 0.000
L1.Burgenland 0.045863 0.019232 2.385 0.017
L1.Kärnten -0.013948 0.010192 -1.368 0.171
L1.Niederösterreich 0.188946 0.040105 4.711 0.000
L1.Oberösterreich 0.303126 0.039182 7.736 0.000
L1.Salzburg 0.109445 0.020547 5.327 0.000
L1.Steiermark 0.104071 0.026815 3.881 0.000
L1.Tirol 0.105681 0.021753 4.858 0.000
L1.Vorarlberg 0.068936 0.018703 3.686 0.000
L1.Wien -0.020403 0.034666 -0.589 0.556
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126854 0.052869 2.399 0.016
L1.Burgenland -0.050006 0.035033 -1.427 0.153
L1.Kärnten -0.040671 0.018567 -2.191 0.028
L1.Niederösterreich 0.170388 0.073055 2.332 0.020
L1.Oberösterreich 0.137816 0.071375 1.931 0.053
L1.Salzburg 0.288782 0.037429 7.716 0.000
L1.Steiermark 0.035736 0.048846 0.732 0.464
L1.Tirol 0.163408 0.039626 4.124 0.000
L1.Vorarlberg 0.101050 0.034070 2.966 0.003
L1.Wien 0.068749 0.063147 1.089 0.276
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055765 0.042015 1.327 0.184
L1.Burgenland 0.039460 0.027840 1.417 0.156
L1.Kärnten 0.051142 0.014755 3.466 0.001
L1.Niederösterreich 0.218280 0.058056 3.760 0.000
L1.Oberösterreich 0.296002 0.056721 5.219 0.000
L1.Salzburg 0.043504 0.029744 1.463 0.144
L1.Steiermark 0.000501 0.038817 0.013 0.990
L1.Tirol 0.143303 0.031490 4.551 0.000
L1.Vorarlberg 0.072256 0.027075 2.669 0.008
L1.Wien 0.080613 0.050182 1.606 0.108
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173585 0.050233 3.456 0.001
L1.Burgenland -0.002375 0.033286 -0.071 0.943
L1.Kärnten -0.062535 0.017641 -3.545 0.000
L1.Niederösterreich -0.077521 0.069413 -1.117 0.264
L1.Oberösterreich 0.189824 0.067816 2.799 0.005
L1.Salzburg 0.057865 0.035562 1.627 0.104
L1.Steiermark 0.234403 0.046410 5.051 0.000
L1.Tirol 0.498596 0.037650 13.243 0.000
L1.Vorarlberg 0.045230 0.032371 1.397 0.162
L1.Wien -0.054780 0.059998 -0.913 0.361
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160001 0.057918 2.763 0.006
L1.Burgenland -0.008089 0.038378 -0.211 0.833
L1.Kärnten 0.065762 0.020340 3.233 0.001
L1.Niederösterreich 0.205026 0.080032 2.562 0.010
L1.Oberösterreich -0.066157 0.078191 -0.846 0.398
L1.Salzburg 0.208643 0.041003 5.088 0.000
L1.Steiermark 0.122012 0.053511 2.280 0.023
L1.Tirol 0.073036 0.043410 1.682 0.092
L1.Vorarlberg 0.120414 0.037324 3.226 0.001
L1.Wien 0.120775 0.069177 1.746 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.359465 0.033264 10.806 0.000
L1.Burgenland 0.007223 0.022042 0.328 0.743
L1.Kärnten -0.023668 0.011682 -2.026 0.043
L1.Niederösterreich 0.214935 0.045965 4.676 0.000
L1.Oberösterreich 0.199657 0.044907 4.446 0.000
L1.Salzburg 0.043609 0.023549 1.852 0.064
L1.Steiermark -0.013303 0.030733 -0.433 0.665
L1.Tirol 0.104770 0.024932 4.202 0.000
L1.Vorarlberg 0.071012 0.021436 3.313 0.001
L1.Wien 0.038290 0.039731 0.964 0.335
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039426 0.139376 0.191580 0.150949 0.117541 0.103077 0.063274 0.216544
Kärnten 0.039426 1.000000 -0.007510 0.132265 0.039239 0.094224 0.432988 -0.053946 0.097328
Niederösterreich 0.139376 -0.007510 1.000000 0.333289 0.142250 0.292808 0.096184 0.179441 0.312854
Oberösterreich 0.191580 0.132265 0.333289 1.000000 0.228726 0.325039 0.175956 0.165814 0.261026
Salzburg 0.150949 0.039239 0.142250 0.228726 1.000000 0.142942 0.112934 0.145190 0.123756
Steiermark 0.117541 0.094224 0.292808 0.325039 0.142942 1.000000 0.146224 0.137146 0.071263
Tirol 0.103077 0.432988 0.096184 0.175956 0.112934 0.146224 1.000000 0.112306 0.142802
Vorarlberg 0.063274 -0.053946 0.179441 0.165814 0.145190 0.137146 0.112306 1.000000 -0.000723
Wien 0.216544 0.097328 0.312854 0.261026 0.123756 0.071263 0.142802 -0.000723 1.000000